package com.example.cinema.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.example.cinema.R;
import com.example.cinema.adapter.UserMasgAdapter;
import com.example.cinema.adapter.UserMasgItemAdapter;
import com.example.cinema.bindingdata.UserMassageItemData;
import com.example.cinema.bindingdata.UserMassgData;
import com.example.cinema.databinding.ActivityUsermsgBinding;
import com.example.cinema.testdara.TestData;

import java.util.ArrayList;
import java.util.List;

//用户消息
public class ActivityUserMessage extends AppCompatActivity {

    private ActivityUsermsgBinding AUB;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AUB = DataBindingUtil.setContentView(this, R.layout.activity_usermsg);
        init();
        initDialog();
        if(Build.VERSION.SDK_INT>11 && Build.VERSION.SDK_INT<19)
        {
            View view = getWindow().getDecorView();
            view.setSystemUiVisibility(View.GONE);
        }else if(Build.VERSION.SDK_INT>=19){
            View view = getWindow().getDecorView();
            int UIOP = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY|View.SYSTEM_UI_FLAG_FULLSCREEN;
            view.setSystemUiVisibility(UIOP);
        }
    }
    List<UserMassgData> data;
    private void init() {
        //消息测试数据
        data = TestData.getMasgData();
        UserMasgAdapter adapter = new UserMasgAdapter(data,R.layout.user_msg_item,getApplicationContext());
        AUB.list.setAdapter(adapter);


        //返回
        AUB.finsh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();

            }
        });

        //清空
        AUB.clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                data.clear();
                Log.i("KKK","长度"+data.size());
                adapter.notifyDataSetChanged();
            }
        });

        //点击查看消息
        AUB.list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                UserMassgData msgdata = data.get(position);
                showDialogs(msgdata);
            }
        });

    }

    //初始弹出消息视图

    private int windowWidth;
    private void  initDialog()
    {

    }

    //跳转到消息详情页
    private void showDialogs(UserMassgData msg)
    {


        Intent intent = new Intent();
        intent.putExtra("sendname",msg.msgsend.get());
        intent.putExtra("sendimg",msg.msgimg.get());
        intent.putStringArrayListExtra("sendlist", (ArrayList<String>) msg.msgbrief.get());
        intent.setAction("msgcontext");
        startActivity(intent);
    }
}
